﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iLangl.Customer.DAL.XMLStorage
{
	public class ConfigurationDAL : BaseStorageDAL, IConfigurationDAL
	{
		private const Int32 PluginConfiguration = 1;



		#region IConfigurationDAL Members

		public string ReadSettings(int settingsId, string siteId)
		{
			dtoXmlStorage.SettingsRow settigs = Storage.Settings.FindBySiteIdSettingsType(siteId, settingsId);

			if (settigs == null)
				return String.Empty;

			return settigs.SettingsContent;
		}

		public void Save(int settingsId, string siteId, string settingsContent)
		{
			dtoXmlStorage.SettingsRow settingsRow = Storage.Settings.FindBySiteIdSettingsType(siteId, settingsId);

			bool isNew = (settingsRow == null);

			if (isNew)
			{
				settingsRow = Storage.Settings.NewSettingsRow();
			}

			settingsRow.SiteId = siteId;
			settingsRow.SettingsType = settingsId;
			settingsRow.SettingsContent = settingsContent;

			if (isNew)
			{
				Storage.Settings.AddSettingsRow(settingsRow);
			}

			AcceptChanges();
		}

		#endregion
	}
}
